
# delim ;  
clear all;
set matsize 11000 ;
eststo clear ;
capture program drop add_lab_FE;
capture log close ; 
log using "compare_MTU_BL.log", text replace;

*Some settings that are common for the set of plots on this dofile; 
local pdf_plot_settings = 	`"scale(*1.5) ymtick(##4) leg(off) "';

*settings for latex tables ;
local tex_settigns  = `" prehead(\begin{table}[H]\centering
	\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
	\caption{@title}
	\setlength{\tabcolsep}{3pt}
	\begin{tabular}{l*{@span}{c}}
	\hline\hline)
	postfoot(\hline\hline
	\multicolumn{@span}{l}{\footnotesize Standard errors clustered by state in parenthesis.  }\\
	\multicolumn{@span}{l}{\footnotesize @starlegend.   }
	\end{tabular}\end{table})	"'	;


	
local tex_settigns_adj  = `" 
	prehead(\begin{table}[H]\centering
	\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
	\begin{adjustbox}{max width=\textwidth,max totalheight=\textheight}
	\caption{@title}
	\begin{tabular}{l*{@span}{c}}
	\hline\hline)
	postfoot(\hline\hline
	\multicolumn{@span}{l}{\footnotesize Standard errors clustered by state in parenthesis.  }\\
	\multicolumn{@span}{l}{\footnotesize @starlegend.   }
	\end{tabular}\end{adjustbox}\end{table})		"'	;
	

*----------------------------------------------------------------------------------;

****************************************;	


use "../data/state_year_all_80_15.dta", clear  ;

*---------------------------------------------------;
* - Generate variables and general cleanings ;
*---------------------------------------------------;

do "_setup_expenditure.do";
do "_cleaning_and_new_variables.do";


tab year periods ;


sum app_IH_r exp_L_IH_SF12a_r;

*------------------------------------------------;
* Run the regressions ;
*------------------------------------------------;

*Add Brooks and Liscow;
xtset state year;

gen statefips=state;

merge 1:1 statefips year   using "../data/20200707_brooks_liscow_annual_data.dta", nogen  ;
ren allMiles all_newmiles;
duplicates tag state_abrev year, gen(xx);
tab xx;
merge m:1 state_abrev year   using "../data/20200707_brooks_liscow_6yrpd_data.dta" ;
sort state year ;
drop xx; 

xtset statefips year;
*- New miles ;
*--------------------------;
gen  allMiles_x=allMiles if allMiles!=0;
gen all_newmiles_x=all_newmiles if all_newmiles!=0;
gen Du_miles_IH_x =Du_miles_IH if Du_miles_IH!=0;
gen scaled_spending_1000=scaled_spending/1000;

gen  exp_L_bridge_IH_SF12a_r = exp_L_IH_SF12a_r + exp_bridge_IH_SF12a_r;

*Transform BL into a stock variable using our miles in 1994; 


gen BL_Miles=u_miles_IH if year==1994 ;

forvalues y = 0(1)38{;

	replace  BL_Miles=f.BL_Miles - all_newmiles if year ==1993-`y';
};


*transform into 2016 prices ;

replace exp_L_bridge_IH_SF12a_r=exp_L_bridge_IH_SF12a_r*ppiaco_2010/ppiaco_2016;
replace exp_L_IH_SF12a_r=exp_L_IH_SF12a_r*ppiaco_2010/ppiaco_2016;


foreach x in u_miles_IH  u_lane_miles_IH BL_Miles{;
	replace `x'=`x'/1000;

};


*Aggregate to a national total;

collapse (sum) allMiles all_newmiles Du_lane_miles_IH u_lane_miles_IH u_miles_IH Du_expantion_miles_IH
			 scaled_spending_1000 exp_L_IH_SF12a_r  exp_L_bridge_IH_SF12a_r BL_Miles Du_miles_IH_x
			 , by(year);

*convert BL to 2016 prices ;

sum exp_L_IH_SF12a_r if year==2016;
		 
* - miles- normalized ;

foreach var in u_miles_IH u_lane_miles BL_Miles{;
	sum `var' if year==1984;
	gen `var'_norm=`var'/r(mean);
};
			 
tw 
   (con   u_miles_IH_norm year if year>1983 , yaxis(1 )
   color(    gs9 )  lp(dash) lw( *2.5) msize( *0.35 5)           )
    (con  u_lane_miles_norm year if year>1983 , yaxis( 1)
   color(  gs0   )  lp(solid ) lw( *2 ) msize( *0.35 )           )
   
   (con BL_Miles_norm  year if year<1994 &  year>1979 ,
lp(dot ) lw(*4 ) msize(*0.35) color( gs4  )) ,
  	xmtick(1980(1)2010)
		xlabel(1980(10)2010)
		xtitle("")

		leg( region(color(none))
			label( 3 "BL-Miles")
			label( 2 "MTU-LM ")
			label( 1 "MTU-Miles")
			 ring(0) pos(5) col(1) size(*.55) order(3 2 1))
			 
			 ymtick(##4)
			 ylabel(, format(%12.2fc))
			 
			ytitle("") 
		scale(*1.5)	; 
			 

	graph export "${output}/figures//FigureA1_compare_MTU_BL.pdf", replace;

		
	
log close;
exit;
